/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Modele;

import java.io.File;
import java.text.Normalizer;
import java.util.Scanner;
import java.util.TreeSet;

/**
 *
 * @author Gloire
 */
public class Dictionnaire extends TreeSet<String>{
    private TreeSet<String> dico;
    
    public Dictionnaire(){
        dico = new TreeSet();
        File liste = new File("./src/Modele/liste_francais.txt");
        try{
            Scanner sc = new Scanner(liste);
            while(sc.hasNext()){
                String str = sc.nextLine();
                if(str.length() > 1 && str.length() < 17)
                    dico.add(Normalizer.normalize(str, Normalizer.Form.NFD));
            }
        }catch(Exception e){
            System.out.println("Fichier introuvable");
        }
        
    }
    
    public Dictionnaire(Case[][] c){
        TreeSet<String> pile = new TreeSet();
        for(int i = 0; i < c.length; i++){
            for(int j = 0; j < c[0].length; j++){
                pile.add(c[i][j].getValeur()+"");
            }
        }
        dico = new TreeSet();
        File liste = new File("./src/Modele/liste_francais.txt");
        String str ;
        try{
            Scanner sc = new Scanner(liste);
            while(sc.hasNextLine()){
                str = sc.nextLine();
                if(str.length() > 1 && str.length() < 17 && pile.contains(str.charAt(0)+"")){
                    dico.add(Normalizer.normalize(str, Normalizer.Form.NFD));
                }
            }
                
        }catch(Exception e){
            System.out.println("Fichier introuvable");
        }
    }
    
    public TreeSet<String> getDico(){
        return dico;
    }
    
    public boolean existe(String s){
        return dico.contains(s);
    }
    
    public boolean commence(String s){
        for(String mot : dico)
            if(mot.startsWith(s))
                return true;
        return false;
    }
}
